home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16716 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  59 lines

  1. Path: news.logicon.com!newsmaster@klee
  2. From: kkolda@logicon.com (Kenneth D. Kolda)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: "Pure virtual function called" error with Sparcworks
  5. Date: 11 Apr 1996 20:52:03 GMT
  6. Organization: Logicon Operating Systems
  7. Message-ID: <4kjrdj$fhi@piper.logicon.com>
  8. References: <316B8607.41C67EA6@jpmorgan.com>
  9. NNTP-Posting-Host: 137.51.122.161
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.99.2
  12.  
  13. In article <316B8607.41C67EA6@jpmorgan.com>, peck_oliver@jpmorgan.com 
  14. says...
  15. >
  16. >I am using V4.0.1 of the Sparcworks C++ compiler.
  17. >
  18. >A program is occasionally crashing with the message:-
  19. >
  20. >"****  Pure virtual function called"
  21. >
  22. >Does anyone know what this may mean?
  23. >
  24. >
  25. >Thanks in advance.
  26. >
  27. >Oliver
  28.  
  29.  
  30. I suspect this is caused by the fact that you're calling a pure virtual 
  31. function in a base class constructor.  For example, if you have
  32.  
  33. class A {
  34.    public:
  35.     A() { Foo(); };
  36.     virtual void Foo() = 0;
  37. };
  38.  
  39. class B : public A {
  40.    public:
  41.     B() {};
  42.     void Foo() {};
  43. };
  44.  
  45.  
  46. main()
  47. {
  48.     B b;
  49. }
  50.  
  51.  
  52. Try this out.  In Sparkworks C++ this should give you the 
  53. "****Pure virtual function called" error and core dump.  According to the 
  54. C++ standards, calling a pure virtual function from a base class 
  55. constructor has undefined results.
  56.  
  57. Ken Kolda
  58.  
  59.